﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Threading;
using System.Globalization;

public partial class NewDistributer : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            
         


        }
        else
        {

        }
    }
    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
                

            }
        }

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
        //ScriptManager.RegisterStartupScript(UpdatePanel8, this.GetType(), "reports", "there();", true);
        GoogleMapForASPNet1.setseen();
    }

    protected void country_SelectedIndexChanged(object sender, EventArgs e)
    {
       
        //24.68632852205518,46.71901702880859
        //24.67291413305010,46.74167633056641
        string code = country.SelectedItem.Text.Split(',')[1];
        code = code.Trim();
        code1.Text = code;
        code2.Text = code;
        code3.Text = code;
        //country.AutoPostBack = false;


    }
    protected void save_Click(object sender, EventArgs e)
    {

        if (Page.IsValid)
        {
            List<string> fields = new List<string>();
            ArrayList values = new ArrayList();
            List<string> types = new List<string>();
            ///////////////



            fields.Add("distributer");
            types.Add("string");
            values.Add(companyname.Text);
           ////////////////////////////////////////////////
            fields.Add("country_id");
            types.Add("string");
            values.Add(country.SelectedValue);
            ///////////////////////
            fields.Add("country");
            types.Add("string");
            values.Add(country.SelectedItem.Text);
            ///////////////////////
            fields.Add("city_id");
            types.Add("string");
            values.Add(city.SelectedValue);
            ///////////////////////
            fields.Add("city");
            types.Add("string");
            values.Add(city.SelectedItem.Text);
            ///////////////////////
            fields.Add("address");
            types.Add("string");
            values.Add(address.Text);
            ///////////////////////
            
            ///////////////////////
            fields.Add("postalcode");
            types.Add("string");
            values.Add(postalcode.Text);
            ///////////////////////
            fields.Add("tele1");
            types.Add("string");
            values.Add( tele1.Text);
            ///////////////////////
            fields.Add("tele2");
            types.Add("string");
            values.Add( tele2.Text);
            ///////////////////////
            fields.Add("fax");
            types.Add("string");
            values.Add( fax.Text);
            ///////////////////////
            fields.Add("email1");
            types.Add("string");
            values.Add(email1.Text);
            ///////////////////////
            ///////////////////////
            fields.Add("website");
            types.Add("string");
            values.Add(username.Text);
            ///////////////////////
            int pointcount = GoogleMapForASPNet1.GoogleMapObject.Points.Count;
            if ( pointcount > 0)
            {
                ///////////////////////
                fields.Add("longitude");
                types.Add("decimal");
                values.Add(GoogleMapForASPNet1.GoogleMapObject.Points[pointcount-1].Longitude);
                ///////////////////////
                fields.Add("latitude");
                types.Add("decimal");
                values.Add(GoogleMapForASPNet1.GoogleMapObject.Points[pointcount-1].Latitude);
                ///////////////////////
            }
            ///////////////////////
            Distributer p = new Distributer();
            p.importfromvalues(fields, values);
            p.setobjecttodatabase(companyname.Text, int.Parse(Session["company_id"].ToString()), Session["user"].ToString().Split(',')[0]);
            DB.setpendingobjectscash();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", " Sents();", true);
            //Response.Redirect("~/companypart/NewDistributer.aspx");
           
        }
    }
    protected void cancels(object sender, EventArgs e)
    {
        Response.Redirect("~/NewDistributer.aspx");

    }
    
    
    
    protected void enter_Click(object sender, EventArgs e)
    {
        
            int pointcount = GoogleMapForASPNet1.GoogleMapObject.Points.Count;
            if (pointcount > 0)
            {
                address.Text = GoogleMapForASPNet1.GoogleMapObject.Points[pointcount-1].InfoHTML;
            }
         
    }

   
}
